package com.jacen.fzxs.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jacen.fzxs.dao.IBaseDao;
import com.jacen.fzxs.dao.IRightDao;
import com.jacen.fzxs.entity.RightEntity;
import com.jacen.fzxs.service.IRightService;
import com.jacen.fzxs.web.Pager;

/**
 * 
 * @author Jacen
 *
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class RightService extends BaseService<RightEntity> implements IRightService {
	
	@Resource
	private IRightDao rightDao;
	
	@Override
	public IBaseDao<RightEntity> getDao() {
		// TODO Auto-generated method stub
		return rightDao;
	}

	@Override
	@Transactional(readOnly = true)
	public List<RightEntity> getPage(Pager pager, Map<String, String> params) throws SQLException {
		pager.setTotalCount(getCount(params));
		return rightDao.getPage((pager.getCurPageNum()-1) * pager.getPageSize() , pager.getPageSize(), params);
	}
	
	@Transactional(readOnly = true)
	public int getCount(Map<String, ? extends Object> params) throws SQLException {
		return rightDao.getCount(params);
	}


	@Override
	public List<RightEntity> getListByUpId(String upId) {
		return rightDao.getListByUpId(upId);
	}

	@Override
	public List<RightEntity> getListByRole(String roleId) {
		return rightDao.getListByRole(roleId);
	}
	
	@Override
	public List<String> getIdsByRole(String roleId) {
		return rightDao.getIdsByRole(roleId);
	}

	@Override
	public void deleteAndChilds(String id) {
		rightDao.deleteByKey("up_right_id", id);
		rightDao.deleteById(id);
	}
	
}
